﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using GlxRRSDB.Utils;
using GlxRRSDB.ReportDataSetTableAdapters;
using GlxRRSDB;
using GlxRRSReporter.DailyReporter;
using GlxRRSDB.Data;
using GlxRRSDB.Facades;
using GlxRRSMain.Utils;

namespace GlxRRSMain.UserControls
{
    public partial class WeeklyReportByCinemaControl : UserControl
    {
        public WeeklyReportByCinemaControl()
        {
            InitializeComponent();
        }

        private void WeeklyReportByCinemaControl_Load(object sender, EventArgs e)
        {
            dpickerD.Value = DateTime.Now;
            loadRangeDateTime();
        }

        private void loadRangeDateTime()
        {
            txtWeekNumber.Text = dpickerD.Value.CurrentWeekNumber().ToString();
            dpickerStart.Value = dpickerD.Value.StartOfWeek(DayOfWeek.Friday);
            dpickerEnd.Value = dpickerD.Value.EndOfWeek(DayOfWeek.Friday);

        }
        private void btnExport_Click(object sender, EventArgs e)
        {
            DateTime dt = dpickerD.Value;
            //
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailAdmission = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailBO = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailCO = new Dictionary<int, Dictionary<DateTime, DailyReportData>>();
            //
            DailyReportFacade.getDetailAdmissionWeek(dt, dictDetailAdmission);
            DailyReportFacade.getDetailBOWeek(dt, dictDetailBO);
            DailyReportFacade.getDetailCOWeek(dt, dictDetailCO);
            // get current date report
            generateDailyReport(dt, dictDetailAdmission, dictDetailBO, dictDetailCO);
        }
        private void generateDailyReport(DateTime d,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailAdmission,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailBO,
            Dictionary<int, Dictionary<DateTime, DailyReportData>> dictDetailCO)
        {
            WeeklyReporterByCinema.init(FileHelper.getWeeklyReportByCinemaTemplate(), FileHelper.genWeeklyReportByCinemaTemplateOut());
            WeeklyReporterByCinema.generateDailyReport(d, dictDetailAdmission, dictDetailBO, dictDetailCO);
        }

        private void dpickerD_ValueChanged(object sender, EventArgs e)
        {
            loadRangeDateTime();
        }
    }
}
